package com.atguigu.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.atguigu.base.BaseDAO;
import com.atguigu.base.BaseServiceImpl;
import com.atguigu.dao.HouseDAO;
import com.atguigu.entity.House;
import com.atguigu.service.CommunityService;
import com.atguigu.service.HouseService;
import com.atguigu.vo.HouseQueryVo;
import com.atguigu.vo.HouseVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @PACKAGE_NAME: com.atguigu.service.impl
 * @CLASSNAME: HouseServiceImpl
 * @AUTHOR: zhangsan
 * @DATE: 2024/4/22 15:31
 * @SINCE 17.0.7
 * @DESCRIPTION: HouseServiceImpl 房源管理
 */

@Service(interfaceClass = HouseService.class)
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
public class HouseServiceImpl extends BaseServiceImpl<House> implements HouseService {

    @Resource
    private HouseDAO houseDAO;

    @Override
    protected BaseDAO<House> getEntityDAO() {
        return houseDAO;
    }

    @Override
    public Integer updateHouseStatus(Long id, Integer status) {
        Integer i = houseDAO.updateHouseStatus(id, status);
        return i;
    }

    @Override
    public House getDictNameById(Long id) {
        House house = houseDAO.getDictNameById(id);
        return house;
    }

    /**
     * 通过前端前台首页传递过来的查询条件查询房源
     *
     * @param pageNum
     * @param pageSize
     * @param houseQueryVo
     * @return
     */
    @Override
    public PageInfo<HouseVo> findListPage(Integer pageNum, Integer pageSize, HouseQueryVo houseQueryVo) {
        PageHelper.startPage(pageNum, pageSize);
        Page<HouseVo> listPage = houseDAO.findListPage(houseQueryVo);
        //分页栏的显示的页数
        PageInfo<HouseVo> pageInfo = new PageInfo<>(listPage, 5);
        return pageInfo;
    }
}
